package koction.model.reviewBoard;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;



import org.springframework.stereotype.Service;

@Service
public class ReviewBoardServiceImpl implements ReviewBoardService {
	@Resource(name="reviewBoardDaoImpl")
	private ReviewBoardDao reviewBoardDao;

	@Override
	public int writeReviewBoard(ReviewBoardVO rvo) {
		return reviewBoardDao.writeReviewBoard(rvo);
	}

	@Override
	public ReviewBoardVO showContentReviewBoard(int reviewNo) {
		reviewBoardDao.updateCountReviewBoard(reviewNo);
		return reviewBoardDao.showContentReviewBoard(reviewNo);
	}

	@Override
	public ReviewBoardVO showContentReviewBoardNoHit(int reviewNo)
			throws SQLException {
		return reviewBoardDao.showContentReviewBoard(reviewNo);
	}
	
	@Override
	public int deleteReviewBoard(int no) {
		return reviewBoardDao.deleteReviewBoard(no);
	}

	@Override
	public ReviewBoardVO updateReviewBoardView(int reviewNo) {
		return reviewBoardDao.showContentReviewBoard(reviewNo);
	}

	@Override
	public int updateReviewBoard(ReviewBoardVO rvo) {
		return reviewBoardDao.updateReviewBoard(rvo);
	}
	
	@Override
	public ArrayList<ReviewBoardVO> getReviewBoardList(String productId) {
		return reviewBoardDao.getReviewBoardList(productId);
	}

	@Override
	public ListVO getReviewBoardListPaging(String pageNo,String productId) {
		if(pageNo==null||pageNo=="") // 목록보기 버튼 누를 경우 최신 글을 보여주기 위해 setting 
			pageNo="1";
		HashMap map=new HashMap();
		map.put("pageNo", pageNo);
		map.put("productId", productId);
		int total=reviewBoardDao.totalContentReviewBoardByproductId(productId);
		PagingBean paging=new PagingBean(total, Integer.parseInt(pageNo));
		List<ReviewBoardVO> list=(List<ReviewBoardVO>) reviewBoardDao.getReviewBoardListPaging(map);
		ListVO lvo=new ListVO(list,paging);
		return lvo;
	}

	

	
}
